//========================================================================================
//  
//  $File: $
//  
//  Owner: Toan Nguyen
//  
//  $Author: $
//  
//  $DateTime: $
//  
//  $Revision: $
//  
//  $Change: $
//  
//  Copyright .
//  
//  
//========================================================================================

#include "VCPlugInHeaders.h"


// Interface includes:
#include "IWidgetUtils.h"
#include "IPanelControlData.h"
#include "IControlView.h"
#include "IActionStateList.h"
#include "ITreeViewController.h"
#include "ITreeViewMgr.h"
#include "ITreeViewHierarchyAdapter.h"
#include "IStringListData.h"

// General includes:
#include "CActionComponent.h"
#include "AMPCAlert.h"
#include "AMPNodeID.h"

#include "K2Vector.tpp" // For NodeIDList to compile

// Project includes:
#include "AMPID.h"
#include "HTTPRequestHelper.h"
/** 	
*/

class AMPActionComponent : public CActionComponent
{
	public:
		/**
			Constructor.
			@param boss interface ptr from boss object on which this interface is aggregated.
		*/
		AMPActionComponent(IPMUnknown* boss);

		/**
			The action component should do the requested action.
			This is where the menu item's action is taken.
			When a menu item is selected, the Menu Manager determines
			which plug-in is responsible for it, and calls its DoAction
			with the ID for the menu item chosen.

			@param actionID identifies the menu item that was selected.
			*/
		virtual void DoAction(IActiveContext *myContext, ActionID actionID, GSysPoint mousePoint, IPMUnknown *widget);
		/**

			Framework will call this method to ask us to update the states of the items.
		*/
		virtual void	UpdateActionStates(IActiveContext *myContext, IActionStateList *listToUpdate, GSysPoint mousePoint, IPMUnknown *widget);

	private:
		/** Encapsulates functionality for the about menu item. */
		virtual void DoAbout();
};

/* CREATE_PMINTERFACE
 Binds the C++ implementation class onto its
 ImplementationID making the C++ code callable by the
 application.
*/
CREATE_PMINTERFACE(AMPActionComponent, kAMPActionComponentImpl)

/* AMPActionComponent Constructor
*/
AMPActionComponent::AMPActionComponent(IPMUnknown* boss)
: CActionComponent(boss)
{
}

/* DoAction
*/
void AMPActionComponent::DoAction(IActiveContext *myContext, ActionID actionID, GSysPoint mousePoint, IPMUnknown *widget)
{

	//cout << "AMPActionComponent::DoAction" << endl;
	
	switch (actionID.Get())
	{
		case kAMPAboutActionID:
		{
			this->DoAbout();
			break;
		}	
		/*
		case kWLBCmpPopupAboutThisActionID:
		case kWLBCmpAboutActionID:
		{
			this->DoAbout();
			break;
		}
		
		case kWLBCmpAddItemActionID:
		{
			this->DoAddItem(widget);
			break;
		}

		case kWLBCmpRemoveItemActionID:
		{
			this->DoRemoveItem(widget);
			break;
		}
		*/
		default:
		{
			break;
		}
	}

}


/* UpdateActionStates

*/

void AMPActionComponent::UpdateActionStates(IActiveContext *myContext, IActionStateList *listToUpdate, GSysPoint mousePoint, IPMUnknown *widget)
{
	do {
		////cout << "AMPActionComponent::UpdateActionStates" << endl;
/*
		int listElementCount = 0;
		InterfacePtr<IControlView> treeWidget(static_cast<IControlView*>(Utils<IWidgetUtils>()->QueryRelatedWidget(widget, kAMPluginListBoxWidgetID, IID_ICONTROLVIEW)));
		ASSERT(treeWidget);
		if(!treeWidget) {
			break;
		}

		InterfacePtr<ITreeViewController> 	controller(treeWidget, UseDefaultIID());
		ASSERT(controller);
		if(!controller)
		{
			break;
		}

		NodeIDList selectedItems;
		controller->GetSelectedItems(selectedItems);
		listElementCount = selectedItems.size();

		for(int i=0; i < listToUpdate->Length(); i++) {

			ActionID action = listToUpdate->GetNthAction(i);
			switch (action.Get())
			{

				//case kWLBCmpRemoveItemActionID:
					if(listElementCount>0) {
						listToUpdate->SetNthActionState(i,kEnabledAction);
					}
					else {
						listToUpdate->SetNthActionState(i,kDisabled_Unselected);
					}
					break;
			}
		}
*/
	} while(0);


}

/********************************************************************************************************************
 *****Function: DoAbout
 *****Creator:  Toan Nguyen
 *****IN: 
 *****out: 
 *****Objective: the version of InDesign plugin
 ********************************************************************************************************************/
void AMPActionComponent::DoAbout()
{//1.1.6
	PMString about("This plugin has been developed for publishers by Audience Media to integrate with the Audience Media CMS.\n\n© Copyright Audience Media – Version 1.0");
	AMPCAlert::ModalAlert
	(
		about,								// Alert string
		"OK",								// OK button
		kNullString,						// No second button
		kNullString,						// No third button
		kNoNeedToWaitForDialog,				// Set OK button to default
		1									// Information icon.
	 );
}
// End, AMPActionComponent.cpp.


